﻿using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace MaterialEditor
{
    /// <summary>
    /// Defines a vertex with position, normal texcoord, and tangent data
    /// </summary>
    public struct PositionNormalTextureTangent : IVertexType
    {
        /// <summary>
        /// The position of the vertex
        /// </summary>
        public Vector3 position;

        /// <summary>
        /// The normal of the vertex
        /// </summary>
        public Vector3 normal;

        /// <summary>
        /// The tangent of the vertex
        /// </summary>
        public Vector4 tangent;

        /// <summary>
        /// The texutre coordinate of the vertex
        /// </summary>
        public Vector2 Uv;

        private static readonly VertexDeclaration _vDeclaration = makeVertexDeclaration();
       VertexDeclaration IVertexType.VertexDeclaration
        {
            get { return _vDeclaration; }
        }

        private static VertexDeclaration makeVertexDeclaration()
        {
            VertexElement[] elements = new VertexElement[]
            {
                new VertexElement(0, VertexElementFormat.Vector3, VertexElementUsage.Position, 0),
                new VertexElement(12, VertexElementFormat.Vector3, VertexElementUsage.Normal, 0),
                new VertexElement(24, VertexElementFormat.Vector4, VertexElementUsage.Tangent, 0),
                new VertexElement(40, VertexElementFormat.Vector2, VertexElementUsage.TextureCoordinate, 0),
            };

            return new VertexDeclaration(elements);
        }

        public PositionNormalTextureTangent(Vector3 position, Vector3 normal, Vector4 tangent, Vector2 uv)
        {
            this.position = position;
            this.normal = normal;
            this.tangent = tangent;
            this.Uv = uv;
        }
    }
}